Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-0 vector-toc-not-available vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-0 vector-feature-night-mode-enabled skin-theme-clientpref-os vector-sticky-header-enabled" lang="fr" dir="ltr"><head>
<meta charset="UTF-8">
<title>Zen de Python</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="./_res_/favicon.png">
<link rel="canonical" href="https://fr.wikipedia.org/wiki/Zen_de_Python"> <link href="./_mw_/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.wikimediamessages.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./_mw_/site.styles.css">
<link rel="stylesheet" type="text/css" href="./_mw_/noscript.css">
<link rel="stylesheet" type="text/css" href="./_res_/footer.css">
<link rel="stylesheet" type="text/css" href="./_res_/vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Zen_de_Python rootpage-Zen_de_Python skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Zen de Python</span></h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="contentSub">
<div id="mw-content-subtitle"></div>
</div>
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="fr" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="fr" dir="ltr">
<p>Le <b>Zen de Python</b> est un ensemble de 19 principes qui influencent la conception du <a href="Python_(langage)" title="Python (langage)">langage de programmation Python</a>, et sont utiles pour comprendre et utiliser le langage<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>.
</p><p>Écrit et publié sur la <a href="Liste_de_diffusion" title="Liste de diffusion">liste de discussion</a> de Python en <time class="nowrap" datetime="1999-06" data-sort-value="1999-06">juin 1999</time> par Tim Peters&nbsp;<a href="https://en.wikipedia.org/wiki/Tim_Peters_(software_engineer)" class="extiw external" title="en:Tim Peters (software engineer)"><span class="indicateur-langue" title="Article en anglais&nbsp;: «&nbsp;Tim Peters (software engineer)&nbsp;»">(en)</span></a><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>, le Zen de Python a été ensuite publié comme le <a href="Python_(langage)#Les_PEP" title="Python (langage)">Python Enhancement Proposal</a> (PEP) numéro 20<sup id="cite_ref-pep20_3-0" class="reference"><a href="#cite_note-pep20-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>. Il est aussi inclus comme «&nbsp;<a href="Easter_egg" title="Easter egg">Easter egg</a>&nbsp;» dans la distribution de l'<a href="Interpr%C3%A8te_(informatique)" title="Interprète (informatique)">interpréteur</a> Python, et apparait quand on tape la commande <code class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><span class="kn">import</span><span class="w"> </span><span class="nn">this</span></code><sup id="cite_ref-pep20_3-1" class="reference"><a href="#cite_note-pep20-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>.
</p><p>Le message initial sur la liste de discussion, comme les publications ultérieures, mentionnent non pas 19, mais 20 principes, «&nbsp;En en comptant un (...) à rajouter par <a href="Guido_Van_Rossum" class="mw-redirect" title="Guido Van Rossum">Guido</a>&nbsp;», mais ce vingtième principe n'a jamais été publié, et n'existe probablement pas. Le texte inclut aussi une référence implicite à <a href="Guido_Van_Rossum" class="mw-redirect" title="Guido Van Rossum">Guido Van Rossum</a> (dans la strophe «&nbsp;à moins d'être <a href="N%C3%A9erlandais_(peuple)" title="Néerlandais (peuple)">Néerlandais</a>&nbsp;»).
</p><p>Le texte en anglais a été mis dans le <a href="Domaine_public_(propri%C3%A9t%C3%A9_intellectuelle)" title="Domaine public (propriété intellectuelle)">domaine public</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Texte">Texte</h2></div>
<p>Une traduction en français a été diffusée sous une <a href="Licence_Creative_Commons" title="Licence Creative Commons">licence Creative Commons</a> <a href="BY-NC-SA" class="mw-redirect" title="BY-NC-SA">BY-NC-SA</a> dans un cours de programmation Python<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>&nbsp;:
</p>
<div class="poem">
<p>Préfère&nbsp;:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;la beauté à la laideur,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l'explicite à l'implicite,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;le simple au complexe<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;et le complexe au compliqué,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;le déroulé à l'imbriqué,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l'aéré au compact.<br>
Prends en compte la lisibilité.<br>
Les cas particuliers ne le sont jamais assez pour violer les règles.<br>
Mais, à la pureté, privilégie l'aspect pratique.<br>
Ne passe pas les erreurs sous silence,<br>
... ou bâillonne-les explicitement.<br>
Face à l'ambiguïté, à deviner ne te laisse pas aller.<br>
Sache qu'il ne devrait [y] avoir qu'une et une seule façon de procéder,<br>
même si, de prime abord, elle n'est pas évidente, à moins d'être Néerlandais.<br>
Mieux vaut maintenant que jamais.<br>
Cependant jamais est souvent mieux qu'immédiatement.<br>
Si l'implémentation s'explique difficilement, c'est une mauvaise idée.<br>
Si l'implémentation s'explique aisément, c'est peut-être une bonne idée.<br>
Les espaces de nommage&nbsp;! Sacrée bonne idée&nbsp;! Faisons plus de trucs comme ça.
</p>
</div>
<p>Les «&nbsp;espaces de nommage&nbsp;» mentionnés dans la dernière strophe désignent les <a href="Espace_de_noms_(programmation)" title="Espace de noms (programmation)">espaces de noms</a> (<i>namespaces</i> en anglais)&nbsp;; ceux-ci assignent un ensemble d'objets (<a href="Entier_relatif" title="Entier relatif">entiers</a>, <a href="R%C3%A9els" class="mw-redirect" title="Réels">réels</a>, <a href="Cha%C3%AEne_de_caract%C3%A8res" title="Chaîne de caractères">chaînes de caractères</a>,&nbsp;<abbr class="abbr" title="et cetera">etc.</abbr>) à un ensemble de termes d'un répertoire<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup><sup class="reference cite_virgule">,</sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Références"><span id="R.C3.A9f.C3.A9rences"></span>Références</h2></div>
<div class="references-small decimal" style=""><div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a> </span><span class="reference-text"><span class="ouvrage" id="2018">«&nbsp;<a rel="nofollow" class="external text" href="https://docs.python.org/fr/3.6/glossary.html#term-zen-of-python"><cite style="font-style:normal;">Zen de Python</cite></a>&nbsp;», sur <span class="italique">Documentation de Python</span>, <time class="nowrap" datetime="2018-11-08" data-sort-value="2018-11-08">8 novembre 2018</time></span></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a> </span><span class="reference-text"><span class="ouvrage"><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> «&nbsp;<a rel="nofollow" class="external text" href="https://mail.python.org/pipermail/python-list/1999-June/001951.html"><cite style="font-style:normal;" lang="en">"The Python Way"</cite></a>&nbsp;», Mail.python.org <small style="line-height:1em;">(consulté le <time class="nowrap" datetime="2018-12-27" data-sort-value="2018-12-27">27 décembre 2018</time>)</small></span></span>
</li>
<li id="cite_note-pep20-3"><span class="reference-text"><span class="ouvrage" id="Peters2004"><span class="ouvrage" id="Tim_Peters2004"><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> Tim Peters, «&nbsp;<a rel="nofollow" class="external text" href="https://www.python.org/dev/peps/pep-0020/"><cite style="font-style:normal;" lang="en">PEP20 -- The Zen of Python</cite></a>&nbsp;», <time class="nowrap" datetime="2004-08-19" data-sort-value="2004-08-19">19 août 2004</time></span></span></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><a href="#cite_ref-4">↑</a> </span><span class="reference-text"><span class="ouvrage" id="CordeauPointal2018"><span class="ouvrage" id="Bob_CordeauLaurent_Pointal2018">Bob Cordeau et Laurent Pointal, «&nbsp;<a rel="nofollow" class="external text" href="https://perso.limsi.fr/pointal/_media/python:cours:courspython3.pdf"><cite style="font-style:normal;">Une introduction à Python 3, version 1.618c</cite></a>&nbsp;», <time class="nowrap" datetime="2018-11-08" data-sort-value="2018-11-08">8 novembre 2018</time></span></span></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><a href="#cite_ref-5">↑</a> </span><span class="reference-text"><span class="ouvrage">«&nbsp;<a rel="nofollow" class="external text" href="https://www.normalesup.org/~doulcier/teaching/python/01_variables.html#Les-espaces-de-noms"><cite style="font-style:normal;">Un point sur les variables et espaces de noms</cite></a>&nbsp;», sur <span class="italique">www.normalesup.org</span> <small style="line-height:1em;">(consulté le <time class="nowrap" datetime="2024-07-11" data-sort-value="2024-07-11">11 juillet 2024</time>)</small></span></span>
</li>
</ol></div>
</div>
<div class="mw-heading mw-heading2"><h2 id="Liens_externes">Liens externes</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://www.python.org/dev/peps/pep-0020/">PEP20 on Python website</a></li></ul>
<ul id="bandeau-portail" class="bandeau-portail"><li><span class="bandeau-portail-element"><span class="bandeau-portail-icone"><span class="noviewer" typeof="mw:File"></span></span> <span class="bandeau-portail-texte">Portail de la programmation informatique</span> </span></li> <li><span class="bandeau-portail-element"><span class="bandeau-portail-icone"><span class="noviewer" typeof="mw:File"></span></span> <span class="bandeau-portail-texte">Portail de la philosophie</span> </span></li> </ul></div><!--htdig_noindex--><div><div class="zim-footer">
Cet article est issu de <a class="external text" title="Dernière modification le 2025-09-28" href="https://fr.wikipedia.org/wiki/?title=Zen_de_Python&amp;oldid=229321620">Wikipédia</a>. Sauf mention contraire, le texte est disponible sous <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.fr">Creative Commons Attribution-Share Alike 4.0</a>. Des conditions supplémentaires peuvent s’appliquer aux fichiers multimédias.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
<script src="./_webp_/webpHandler.js"></script>

</body></html>